import json
import os


# 将给定时间以及基站数量写为json文件
def create_cheat(time_id, bs_num, data):
    """

    :param time_id:
    :param bs_num:
    :param data: 计划返回的数据
    :return:
    """
    # 路径的格式
    res_return = data
    directory = f"data_store/bs{bs_num}"
    if not os.path.exists(directory):
        os.makedirs(directory)
    path = f"{directory}/time{time_id}final.json"

    with open(path, 'w') as file:
        json.dump(res_return, file)


def create_cheat_user(time_id, bs_num, data):
    """
    用户位置信息
    :param time_id:
    :param bs_num:
    :param data: 计划返回的数据
    :return:
    """
    # 路径的格式
    res_return = data
    directory = f"data_store/bs{bs_num}"
    if not os.path.exists(directory):
        os.makedirs(directory)
    path = f"{directory}/time{time_id}user.json"

    with open(path, 'w') as file:
        json.dump(res_return, file)


def create_cheat_bs(time_id, bs_num, data):
    """
    基站位置信息
    :param time_id:
    :param bs_num:
    :param data: 计划返回的数据
    :return:
    """
    # 路径的格式
    res_return = data
    directory = f"data_store/bs{bs_num}"
    if not os.path.exists(directory):
        os.makedirs(directory)
    path = f"{directory}/time{time_id}bs.json"

    with open(path, 'w') as file:
        json.dump(res_return, file)


# def get_cheat(time_id, bs_num):
#     directory = f"data_store/bs{bs_num}"
#     path = f"{directory}/time{time_id}bs.json"
#     with open(path, 'r') as file:
#         data = json.load(file)
#     return data

def get_cheat(time_id, bs_num):
    # 获取当前脚本所在的目录，即项目根目录
    root_dir = os.path.dirname(os.path.abspath(__file__))
    directory = f"data_store/bs{bs_num}"
    path = os.path.join(root_dir, directory, f"time{time_id}final.json")
    with open(path, 'r') as file:
        data = json.load(file)
    return data

def get_cheat_bs(time_id, bs_num):
    # 获取当前脚本所在的目录，即项目根目录
    root_dir = os.path.dirname(os.path.abspath(__file__))
    directory = f"data_store/bs{bs_num}"
    path = os.path.join(root_dir, directory, f"time{time_id}bs.json")
    with open(path, 'r') as file:
        data = json.load(file)
    return data

def get_cheat_user(time_id, bs_num):
    # 获取当前脚本所在的目录，即项目根目录
    root_dir = os.path.dirname(os.path.abspath(__file__))
    directory = f"data_store/bs{bs_num}"
    path = os.path.join(root_dir, directory, f"time{time_id}user.json")
    with open(path, 'r') as file:
        data = json.load(file)
    return data